<?php

class User extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'user':
	 * @var string $username
	 * @var string $password
	 * @var string $email
	 * @var string $language
	 * @var string $first_name
	 * @var string $last_name
	 * @var string $phone_number
	 * @var string $initials
	 * @var bool $simulation
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('username','length','max'=>20),
			array('password','length','max'=>50),
			array('email','length','max'=>255),
			array('language','length','max'=>5),
			array('first_name','length','max'=>100),
			array('last_name','length','max'=>100),
			array('phone_number','length','max'=>50),
			array('initials','length','max'=>3),
			array('simulation', 'boolean'),
			array('username, password, email, first_name, initials', 'required'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'username' => Yii::t('database', 'Username'),
			'password' => Yii::t('database', 'Password'),
			'email' => Yii::t('database', 'Email'),
			'language' => Yii::t('database', 'Language'),
			'first_name' => Yii::t('database', 'First Name'),
			'last_name' => Yii::t('database', 'Last Name'),
			'phone_number' => Yii::t('database', 'Phone Number'),
			'initials' => Yii::t('database', 'Initials'),
			'simulation' => Yii::t('database', 'Simulation'),
		);
	}

	public function getFullName()
	{
		return sprintf (
			"%s%s%s", 
			($this->last_name == null ? "" : $this->last_name),
			($this->first_name != null && $this->last_name != null ? " " : ""),
			($this->first_name == null ? "" : $this->first_name)
		);
	}
}